<?php

require_once "../lib/nusoap/lib/nusoap.php";
function getProd($category) {
    if ($category == "books") {

        return join(",", array(
            "The WordPress Anthology",
            "PHP Master: Write Cutting Edge Code",
            "Build Your Own Website the Right Way"));
    } else {
        return "No products listed under that category";
    }
}

function getProduct() {
    return "SpiderCrawler";
}

function getAsh() {
    return "Ashwitha";
}

function getPublication($year, $author) {
    if ($year == "2010") {
        if ($author == "Herbert") {
            return join(",", array("Tata McGrawHill, Himalya Publication, Pearson Publication, Arihant Publication"));
        }
    }
}

$server = new soap_server();
$server->configureWSDL("IndexerService", "urn:IndexerService");
//$server->register("getProd");
//$server->register("getProduct");
//$server->register("getAsh");
//$server->register("getPublication");
//$server->register("indexDocument");
$server->register('indexDocument',                // method name
    array('documentData' => 'xsd:string', 'url' => 'xsd:string'),        // input parameters
    array('return' => 'xsd:string'),      // output parameters
    'urn:IndexerService',                      // namespace
    'urn:IndexerService#indexDocument',                // soapaction
    'rpc',                                // style
    'encoded',                            // use
    'Says hello to the caller'            // documentation
);

function indexDocument($documentData,$url) {
//    if (stripos($documentData, 'real')) {
//        $bFound = TRUE;
//    }
//    if($documentData != NULL) {
//        return "".$documentData;
//    }
    require_once '../Crawler/Indexer.php';

    $Indexer = new Indexer();
    $Indexer->fillDictionary();
    return $Indexer->processDocument($documentData,$url);
}

// Use the request to (try to) invoke the service
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
exit();
